//
//  ___FILENAME___
//  ___PROJECTNAME___
//
//  Created by ___FULLUSERNAME___ on ___DATE___.
//___COPYRIGHT___
//

#import "___FILEBASENAMEASIDENTIFIER___.h"
#import "___VARIABLE_classPrefix:identifier___User.h"

#define kAppContextCacheUser    @"kAppContextCacheUser"
#define kAppContextCacheToken    @"kAppContextCacheToken"

@implementation ___FILEBASENAMEASIDENTIFIER___

+ (instancetype)sharedInstance
{
    static id instance = nil;
    static dispatch_once_t onceToken;
    dispatch_once(&onceToken, ^{
        instance = self.new;
    });
    return instance;
}

- (instancetype)init
{
    if (self = [super init]) {
        
    }
    return self;
}

- (void)setUser:(___VARIABLE_classPrefix:identifier___User *)user
{
    if (_user != user) {
        _user = user;
        [self saveUser];
        
        if (user.token.length > 0) {
            self.token = user.token;
        }
    }
}

- (void)setToken:(NSString *)token
{
    if (_token != token) {
        _token = token;
        
        RFCache.sharedCache[kAppContextCacheToken] = token;
    }
}

- (void)saveUser
{
    RFCache.sharedCache[kAppContextCacheUser] = self.user;
}

@end
